Part Number Hot Search : 
PWT100 AM9513PC 0N60B2 CNY17106 GL032N90 K1603T06 C1204 B950A
Product Description
Full Text Search
 

To Download UM0144 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  stmicrolectronics st7 assembler linker UM0144 user manual rev 2 june 2005
blank
rev 2 june 2005 UM0144 3/92 4 UM0144 user manual st7 assembler linker introduction thanks for choosing st7! this manual describes how to use the st7 assembler-linker to develop applications for st7 microcontrollers. the assembly tools described in this book form a development system that assembles, links and formats your source code. the st7 assembler-linker includes the following tools: assembler (asm) : translates your source code ( .asm ) written in assembly language, into object code ( .obj ) specific to the target machine and an optional listing file ( .lst ). linker (lyn) : processes the object files ( .obj ) produced by the assembler, resolves all cross-references between object files and locates all the modules in memory. the resulting code is output in an object code file ( .cod ). in a second pass, the assembler uses these files to produce an object code file, map and listing with absolute paths. obsend (obs) : translates the object code file to produce the final executable in a default format ( .fin ) or other format that you specify (e.g. st s-record, motorola s-record, intel hex...). lib (librarian) : the librarian enables you to store frequently used subroutines in one location for use with any number of st7 applications. figure 1. schematic overview of the st7 assembler toolset www.st.com
st7 assembler linker 4/92 UM0144 note: the utility file asli.bat automatically runs asm, lyn, and obsend one after the other for you. use this batch file only if you have only one assembly source file ".asm". about the user manuals... this manual provides information about producing an application executable for st7 from your application source code in assembly language. here, you will find: an overview of assembly language for st7 instructions for running the st7 assembler-linker descriptions of the assembler output for information on related subjects refer to the following documentation: st7xxxx datasheet ? full description of your st7. st7 programming manual ? a complete reference to st7 assembly language host pc system requirements this tool has been designed to operate on a pc that meets the following: one of the following operating systems: microsoft ? windows ? 98, 2000, millennium, nt ? or xp ? . intel ? pentium (or compatible) processor with minimum speed of 133 mhz. minimum ram of 32 mb (64 mb recommended). 60 mb of free hard disk space to install all of the st7 tools. getting assistance for more information, application notes, faqs and software updates for all the st microcontroller development tools, check out the cd-rom or our website: www.st.com/mcu for assistance on all st microcontroller subjects, or for help developing applications that use your microcontroller?s msci peripheral, refer to the contact list provided in product support on page 108. we?ll be glad to help you.
st7 assembler linker UM0144 5/92 contents 1 getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2 st7 addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.1 overview of st7 addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2 general instruction syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3 short and long addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.4 inherent addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.5 immediate operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.6 direct and indirect modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.7 indexed modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 2.8 relative mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 2.9 high, low addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 3 st7 assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2 source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 assembly source code format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.4 segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.5 macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.6 conditional assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.7 running the assembler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4 linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.1 what the linker does . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.2 invoking the linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.3 command line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.4 linking in detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.5 the linker in more detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 5 obsend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 5.1 what obsend does for you . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 5.2 invoking obsend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
st7 assembler linker 6/92 UM0144 6 librarian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 6.1 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 6.2 invoking the librarian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 6.3 adding modules to a library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 6.4 deleting modules from a library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 6.5 copying modules from a library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 6.6 getting details in your library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 appendix a assembler directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 appendix b error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 appendix c revision history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 appendix d product support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
st7 assembler linker 1 getting started UM0144 7/92 1 getting started installing the st7 assembler-linker the st7 assembler-linker is delivered as part of the st7 toolset. a free installation package is available at www.st.com/mcu . to install it: 1. select st7>st7 toolchain from the main menu of the ?microcontroller development tools? cd-rom, or... 2. run the installation executable that you have downloaded from the internet. note: windows ? 2000, nt ? and xp ? users must have administrator privileges to install certain software components. after installation, the installation directory should contain the following ( table 1 ) : . up-to-date release notes are provided in pdf format. an additional file contains demonstration examples. table 1. description of installed files asm.exe st7 assembler lyn.exe st7 linker obsend.exe output file formatter lib.exe librarian st7.tab st7 description files asli.bat batch file asm+lyn+obsend release_notes.pdf release notes
2 st7 addressing modes st7 assembler linker 8/92 UM0144 2 st7 addressing modes 2.1 overview of st7 addressing modes the st7 assembler instruction set incorporates the following different addressing modes: all st7 addressing modes are described in full detail, with specific examples, in the st7 family 8-bit mcus programming manual . this chapter seeks only to give a brief explanation of the main addressing mode types. 2.2 general instruction syntax the st7 instruction set provide a single source-coding model regardless of which components are operands?the accumulator (a), an index register (x or y), an 8-bit stack pointer (s) for st7, the condition code register (cc), or a memory location. for example, a single instruction, ld , originates register to register transfers as well as memory to accumulator data movements. table 2. st7 addressing modes instruction set addressing mode example st7 inherent nop immediate ld a,#$f5 direct (short address) ld a,$f5 direct (long address) ld a,$f5c2 x or y indexed (no offset) ld a,(x) x or y indexed (short offset) ld a,($f5,x) x or y indexed (long offset) ld a,($f5c2,x) short pointer indirect (short pointed data) ld a,[$f5] short pointer indirect (long pointed data) ld a,[$f5.w] short pointer indirect (short pointed data) x or y indexed ld a,([$f5],x) short pointer indirect (long pointed data) x or y indexed ld a,([$f5.w],x) direct relative (short offset) jrt $f5 short pointer indirect relative (short pointed data) jrt [$f5] bit operation bset byte, #5
st7 assembler linker 2 st7 addressing modes UM0144 9/92 two-operand instructions are coded with destination operand appearing at first position. for example: 2.3 short and long addressing modes for st7 there are two addressing modes that differ in memory address size (i.e. one byte for short mode and two bytes for long mode). because of these different addressing modes, the target address range of the operands will depend upon the addressing mode chosen: some instructions accept both long and short addressing modes, while others only accept one or the other. for example: for st7 instructions supporting both short and long formats, when external symbols are referenced, long mode is chosen by the assembler. for example: 2.4 inherent addressing mode this concept is hardware-oriented, meaning that instruction operands are coded inside the operation code. at the source coding level, operands are written explicitly. examples: lab01 ld a,memory ; load accumulator a with memory contents lab02 ld memory,a ; load memory location with a contents ld x,a ; load x with accumulator contents 0-$ff for short addressing mode $100-$ffff for long addressing mode lab10 add a,memory ; accepts both types of addressing modes lab11 inc memory ; accepts only short addressing mode extern symb3 ; symb1 equ $10 ; ... ld a,symb1 ; short mode ld a,symb3 ; long mode chosen lab06 push a ; put accumulator a onto the stack lab07 mul x,a ; multiply x by a
2 st7 addressing modes st7 assembler linker 10/92 UM0144 2.5 immediate operands immediate operands permit you to input a specific value for use with an instruction. they are signaled by the use of a sharp sign (#) before the value. examples: the range for an 8-bit immediate operand is from 0 to 255. 2.6 direct and indirect modes a direct addressing mode means that the data byte required to do the operation is found by its memory address, which follows the op-code. an indirect addressing mode means that the data byte required to do the operation is found by its memory address which is located in memory (pointer). the pointer address follows the op-code. this last group consists of memory indirect variants: short indirect (short pointed data), long indirect (long pointed data), short indirect indexed (short pointed data), long indirect indexed (long pointed data), for st7 devices, the address specified must always be in page 0 (i.e. its address must be less than $100). examples: to make the distinction between short and long indirect addressing mode, the suffix .w is specified to indicate that you want to work in long indirect mode (this is also true for indexed addressing mode). implicitly, if nothing is specified, the short indirect addressing mode is assumed. for st7 devices, you can also use .b to specify short indirect addressing mode (as with the indexed addressing mode). lab08 ld a,#1 ; load a with immediate value 1 lab09 bset memory,#3 ; set bit #3 in memory location btjt memory,#3,label ; test bit #3 of memory and jump if true (set) ld a,[80] ; short indirect ld a,[80.b] ; short indirect ld a,[80.w] ; long indirect lab12 equ 80 ld a,([lab12],x) ; short indirect x-indexed ld a,([lab12.b],x) ; short indirect x-indexed ld a,([lab12.w],y) ; long indirect y-indexed
st7 assembler linker 2 st7 addressing modes UM0144 11/92 2.7 indexed modes the st7 hardware supports four types of indexed mode: indexed without offset, indexed with a 8-bit unsigned offset (range [0 ,255]), indexed with a 16-bit offset, the source coding syntax is: (x) or (y) for no-offset indexing. (offset,x) or (offset,y) for indexed with offset. some instructions (such as ld a or add ) support the first three types of indexed mode. some st7 instructions (such as inc ) only support the first two types (i.e. indexed without offset and indexed with 8-bit unsigned offset). examples: 2.8 relative mode this addressing mode is used to modify the program counter (pc) register value by adding an 8-bit signed offset to it (i.e. in the range -128 to +127). the relative addressing mode is made up of two sub-modes: relative (direct) ?where the offset is following the op-code. relative (indirect) ?where the offset is defined in memory, whose address follows the op- code. relative mode is used by the instructions jrxx, callr, and btjx . at source coding level, the target label is specified (and the assembler computes the displacement). 2.9 high, low addressing modes in some instances, it may be necessary to access the highest part of an address (8 highest bits) or the lowest part of an address (8 lowest bits) as well. for this feature, the syntax is the following one: < expression > where expression is: symbol.h (highest part) , or symbol.l (lowest part). ld a,(x) ; no-offset mode ld a,(0,x) ; 8-bit offset mode ld a,(127,x) ; 8-bit offset mode ld a,(259,x) ; 16-bit offset mode
2 st7 addressing modes st7 assembler linker 12/92 UM0144 examples: for more information about each instruction and the various addressing modes, refer to the st7 programming manual , which can be downloaded from the internet at www.st.com/mcu . lab12 equ $0012 nop ld a,#lab12.h ; load a with $00 ld a,#lab12.l ; load a with $12
st7 assembler linker 3 st7 assembler UM0144 13/92 3 st7 assembler 3.1 overview the st7 assembler program is a cross-assembler, meaning that it produces code for a target machine?an st7 microprocessor?which is different from the host machine. the assembler turns your source code files into relocatable object modules ready for linking. during the process, it checks for many different types of errors. these errors are recorded in an ascii file called cbe.err . (note that the linker also writes to this file.) error messages are explained in on page 78. to produce code ready for execution, you must run the assembler ( asm ), the linker ( lyn ), and the object code formatter ( obsend ). 3.2 source files source program code is written in the st7 assembler language and is saved in an ascii text file named source file . a source file has the extension .asm . it is made up of lines, each of which is terminated by a new line character. for a complete reference to the st7 assembler language, refer to the st7 programming manual . 3.3 assembly source code format the first line of an assembly source code file is reserved for specifying the *.tab file for the target processor . you cannot put other instructions or comments in this line. use this line to specify the directory location of the *.tab file. if the directory is not specified, by default the assembler searches first in the current directory, then in the directory where the assembler?s executable is located. the '.tab' suffix may be left out?as the assembler only looks for this file type. for example, the first line of your source code might look like: c:\st7tools\asm\st7\ if the file st7.tab can't be found in the specified or default directories, then an error is produced and assembly is aborted. the rest of the source code lines have the following general format: [label[:]][opcode][operand][;comment] where refers to either a space ( $20 ) or a tab ( $09 ) character. all four fields may be left blank, but the fields are mandatory unless: the whole line is blank, or the line begins as a comment, or the line ends before the remaining fields.
3 st7 assembler st7 assembler linker 14/92 UM0144 for example: the next sections describe the main components of a source code file. 3.3.1 about labels label structure labels must start in column one. a label may contain up to 30 of any of the following characters: upper case letters (a-z) lower case letters (a-z) digits (0-9) underscore (_) the first letter of a label must be a letter or an underscore. note that upper and lower case are treated differently because the assembler is case sensitive. upon assembly, any label that exceeds 30 characters is truncated and a warning alerts the user that this has occurred. when truncated, if two of more labels have the same name, a phase inconsistency error is generated. when labels are defined, several attributes are defined along with the value. these are: size (byte, word or long) relativity (linker relative or absolute) scope (internally or externally defined) the function of each attribute is explained in the following sections. label size defining a label?s size allows the assembler to determine what kind of addressing mode to choose even if the value associated with the label is undefined. the default size of the memory location for a label is word (2 bytes). whenever the label has no suffix, then the default size is assumed. the directives bytes , words and longs (4 bytes) allow you to change the default. regardless of the default size, you can define the size for a specific label by adding a suffix to it: .b for byte, .w for word and .l for long. the suffix is not used when the label is referred to. using of any suffixes other than .b, .w and .l will result in an error upon assembly. examp ld a,$ffff ; long addressing mode comments operand opcode label separator
st7 assembler linker 3 st7 assembler UM0144 15/92 for example: label relativity there are two sorts of labels: absolute labels and relative labels. absolute labels are usually assigned to constants, such as io port addresses, or common values used within the program. relative labels are defined as (or derived from) an external label or a label derived from the position of some program code. they are exclusively used for labels defined within pieces of program or data. for example: only the linker can sort out the actual address of the code, as the assembler has no idea how many segments precede this one in the class. at assembly time, labels such as ' start ' or ' loop ' are actually allocated 'blank' values ($0000). these values will be filled later by the linker. labels such as ' count ' or ' ioport ', which were defined absolutely will be filled by the assembler. source code lines that have arguments containing relative labels are marked with an 'r' on the listing, showing that they are 'linker relative'. segments are discussed in section 3.4 on page 22. lab equ 0 ; word-size label (default) label1.b equ 5 ; byte-size label label2.l equ 123 ; long label segment byte at: 80 ?ram? bytes ; force the size of the label to ; bytes count ds.b ; byte-size label pointer ds.w ; byte-size label with a word-size ; space reserved at this address lab equ 0 ; absolute label ?count? ioport equ $8000 ; absolute word label ?ioport? segment ?eprom? start ld x,#count ld a,#?*? loop ld ioport,a dec x jrne loop stop jp stop ; then loop for ever
3 st7 assembler st7 assembler linker 16/92 UM0144 label scope often, in multi-module programs, a piece of code will need to refer to a label that is actually defined in another module. to do this, the module that exports the label must declare it public, and the module which imports the label must declare it extern. the two directives extern and public go together as a pair. most labels in a program will be of no interest for other pieces of the program?these are known as 'internal' labels since they are only used in the module where they are defined. labels are 'internal' by default. here are two incomplete example modules that pass labels between them: as you can see, module 1 refers to the ' _sig2' subroutine which is defined in module 2. note that when module 1 refers to the ' _sig2 ' label in an extern directive it specifies a word size with the ' .w ' suffix. because the assembler cannot look up the definition of ' _sig2 ' it has to be told its address size explicitly. it doesn't need to be told relativity: all external labels are assumed to be relative . absolute labels declared between modules should be defined in an include file that is called by all modules in the program; this idea of using include files is very important since it can reduce the number of public symbols?and therefore the link time?significantly. lines in the source code listing which refer to external labels are marked with an x and given 'empty' values for the linker to fill. module 1 extern _sig1.w ; import _sig1 extern _sig2.w ; import _sig2 public _handlers ; export _handlers segment byte ?p? _handlers: ; define _handlers jp _sig1 ; refer to _sig1 jp _sig2 ; refer to _sig2 end module 2 extern _handlers.w ; import _handlers (addr. is a word) public _sig2 ; export _sig2 segment byte ?p? _sig2: ; define _sig2 ... call _handlers ; refer to _handlers ... ret end
st7 assembler linker 3 st7 assembler UM0144 17/92 as a short cut, labels may be declared as public by preceding them with a ' . ' at their definition. if this is done the label name need not be given in a public directive. for example, the following code fragment declares the label ' lab4 ' as public automatically: 3.3.2 about opcodes the opcode field may serve three different purposes. it may contain: the opcode mnemonic for an assembly instruction, the name of a directive, the name of a macro to be invoked. opcodes must be separated from the preceding field (i.e. label, if there is one) by a space or a tab. a comprehensive opcode description can be found in the st7 programming manual . macros are discussed in section 3.5 on page 26. directives are discussed in on page 48. 3.3.3 about operands operands may be any of the following: numbers and addresses, string and character constants, program counter references, expressions. the following paragraphs explain how to use these types of operands. number and address representation by default, the representation of numbers and addresses follows the motorola syntax. when you want to use hexadecimal number with instructions or labels, they must be preceded by $. when nothing is specified, the default base is decimal. for example: lab3 ld a,#0 ret .lab4 nop ret lab03 equ 10 ; decimal 10 lab04 equ $10 ; hexadecimal 10 ld a,$ffff ; long addressing mode ld a,#$cb ; immediate addressing mode ld a,#100 ; decimal representation
3 st7 assembler st7 assembler linker 18/92 UM0144 you can change the motorola format representation by using directives (.intel, .texas) to indicate the new setting format. for more information, refer to on page 48. caution: addresses for segment definition are always given in hexadecimal: segment byte at: 100-1ff 'test' the segment ' test ' is defined within the 256-511 address range. numeric constants and radix constants may need special characters to define the radix of the given number. the assembler supports the motorola format by default. intel, texas, zilog formats are also available if the format is forced by .intel .texas or .zilog directives. ta bl e 3 on page 18 shows a summary of these formats. note: decimal constants are always the default, and require no special characters. string constants string constants are strings of ascii characters surrounded by double quotes . for example: ascii character constants the assembler's arithmetic parser also handles ascii characters in single quotes , returning the ascii of the given character(s). for example: table 3. numeric constants and radix formats format hex binary octal current pc motorola $abcd or &abcd %100 ~665 * (use mult for multiply) intel 0abcdh 100b 665o or 665q $ texas >abcd ?100 ~665 $ zilog %abcd %(2)100 %(8)665 $ ?this is an ascii string? ?a? $41 ?6? $06 ?ab? $4142
st7 assembler linker 3 st7 assembler UM0144 19/92 up to 4 characters may be used within a single pair of quotes to give a long constant. the following special sequences are used to denote special characters: program counter reference the current value of the program counter (pc) can be specified by an asterisk " * ". for example: expressions and operators expressions are numeric values that may be made up from labels, constants, brackets and operators. labels and constants have been discussed in previous paragraphs. arithmetic brackets are allowed up to 8 nested levels ?the curly braces {} are used instead of the common ?()? because instructions may use a parenthesis to denote indexed addressing modes. ?\b? $7f backspace ?\f? $0c formfeed ?\n? $0a linefeed ?\r? $0d carriage return ?\t? $09 tabulation ?\\? $5c slash ?\? $27 single-quote ?\0? $00 null ?\?? $22 double-quote lab05 jra *
3 st7 assembler st7 assembler linker 20/92 UM0144 operators have 4 levels of precedence. operators in level #1 (listed in ta b l e 4 ) take precedence over operators in level #2 (listed in ta b l e 5 ), and so on. in each level, operators have same precedence?they are evaluated from left to right. table 4. level 1 operators operation result, level #1 -a negated a a and b logical and of a and b a or b logical or of a and b a xor b logical xor of a and b a shr b a shifted right b times a shl b a shifted left b times a lt b 1 if ab, else 0 a eq b 1 if a=b, else 0 a ge b 1 if a>=b, else 0 a ne b 1 if a unequal b, else 0 high a a/256, force arg to byte type low a a mod 256, force arg to byte type offset a a mod 65536, force arg to word*16 type seg a a/65536, force arg to word*16 type bnot a invert low 8 bits of a wnot a invert low 16 bits of a lnot a invert all 32 bits of a sexbw a sign extend byte to 16 bits sexbl a sign extend byte a to 32 bits sexwl a sign extend word to 32 bits table 5. level 2 operators operation result, level #2 a/b a divided by b a div b a divided by b table 6. level 3 operators operation result, level #3 a * b a multiplied by b a mult b as above for motorola (character * is reserved)
st7 assembler linker 3 st7 assembler UM0144 21/92 operator names longer than one character must be followed by a space character. for example, ' 1 and 2 ' is correct, ' 1and2 ' is not. place the curly braces { } around arithmetic expressions. also, always use curly braces at the top-level, when defining a numeric expression. not doing so may produce unexpected results. 3.3.4 comments comments are preceded by a semicolon. characters following a semicolon are ignored by the assembler. 3.3.5 a source code example below is an example of a short source code. table 7. level 4 operators operation result, level #4 a-b a minus b a+b a plus b wrong syntax: #define size 128 ds.w size+1 ; wrong, syntax error #if size eq 1 ; wrong, same as #if size #endif correct syntax: #define size 128 ds.w {size+1} ; ok #if {size eq 1} ; ok #endif st7/ ; small example module showing source formats ioport equ $8000 ; 8 bit i0 port a handshake equ $9000 ; write xx here to strobe segment 'program' start ld a,#0 ; zero counter loop ld ioport,x ; store into ioport
3 st7 assembler st7 assembler linker 22/92 UM0144 don't worry if some directives don't make sense yet; they will be covered soon. also, take special notice of the segment directive. 3.4 segmentation segments are very important. you have to understand segments before you can use the assembler. take the time to understand them now and you'll save yourself a lot of puzzling later. segmentation is a way of 'naming' areas of your code and making sure that the linker collates areas of the same name together in the same memory area, whatever the order of the segments in the object files. up to 128 different segments may be defined in each module. the segment directive itself has four arguments, separated by spaces: [] segment [] [] '' [cod] for example: segment word at: fffc 'code' word start end file1: st7/ bytes segment byte at: 80-ff ?ram0? counter.b ds.b ; loop counter address.b ds.w ; address storage ds.b 15 ; stack allocation stack ds.b ; stack grows downward segment byte at: e000-ffff ?eprom? ld a,#stack ld s,a ; init stack pointer end
st7 assembler linker 3 st7 assembler UM0144 23/92 in the preceding example, file1 and file2 are two separate modules belonging to the same program. file1 introduces two classes: 'ram0' and 'eprom' . the class-names may be any names you choose up to 30 characters. the first time a class is used?introduced?you have to declare the default alignment, the start and the end addresses of the class, and of course, the name of the class. users generally specify a new class for each 'area' of their target system. in the examples above, the user has one class for the 128 bytes of on-chip ram from 0080 to 00ff ( 'ram0' ) and another for the 'eprom' . the code is stored from e000 to ffff ( 'eprom' ). you have to supply all this information the very first time you use a new class, otherwise only the class-name is necessary, as in file2. 3.4.1 parameters the following paragraphs describe each argument in detail. name the argument is optional; it can contain a name of up to 12 characters. if it does, then all segments with the same name are grouped together within their class, in the order that new names are defined. align the argument defines the threshold on which each segment must start. the default is the alignment specified at the introduction of the class (if none is specified in the class introduction then para alignment is assumed), although the alignment types described in ta b l e 8 are allowed to be specified overriding the default. file2: st7/ segment ?ram0? serialtemp ds.b serialcou ds.b words segment ?eprom? serial_in ld a,#0 end
3 st7 assembler st7 assembler linker 24/92 UM0144 looking back to our example on page 22 , you should now be able to see that the 'ram0' class will allocate 80 to counter , 81 to address , 92 to stack in file1, and when the linker meets the segment in file2 of the same class, serialtemp will be allocated 93 , and serialcou 94 . the same processing happens to the two 'eprom' class segments?the second, in file2, will be tacked on to the end of the first in file1. if the file2 'eprom' class segment had specified, say, the long align type instead of the default byte , then that segment would have been put on the next long-word boundary after the end of the file1 'eprom' class segment. combine the argument tells the assembler and linker how to treat the segment. there are three types to handle it: the at -type must be used at the introduction of a class, only once . the at -type must have one argument: the start address of the class, and may optionally be given the end address (or limit) of the class too. if given, the linker checks that no items in the class have gone over the limit address; if this does occur, a warning is issued at link time. the hexadecimal numbers x and y should not have radix specifiers. all common -type segments that have the same class name will start at the same address. the linker keeps track of the longest segment. common segments can be used for sharing data across different applications. table 8. alignment types type description examples byte any address word next address on boundary 1001->1002 para next address on 16-byte boundary 1001->1010 64 next address on 64-byte boundary 1001->1040 128 next address on 128-byte boundary 1001->1080 page next address on 256-byte boundary 1001->1100 long next address on 4-byte boundary 1001->1004 1k next address on 1k-byte boundary 1001->1400 4k next address on 4k-byte boundary 1001->2000 table 9. combine types type description at:x[-y] starts a new class from address x [to address y] common all common segments that have the same class name will start at the same address. this address is determined by the linker. follows on from end of last segment of this class.
st7 assembler linker 3 st7 assembler UM0144 25/92 for example: the values for labels lab1 , lab2 , lab3 , lab4, and lab5 are 12 , 12 , 1a , 1a and 1e, respectively. note: since you can't specify both at and common combines simultaneously, the only way to specify the exact location of commons is to insert an empty at combine segment before the first common declaration. for example: cod parameter, out put file control the last field of a segment directive controls where the linker places the code for a given class. when introducing a class, if this field is not specified, the code for this class will be sent to the normal, default .cod file by the linker. if the [cod] file is given a number between 0 and 9 then all code generated under the class being introduced will be sent to a different '.cod ' file by the linker. if the linker produces a file called ' prog.cod ', for example, then all code produced under classes with no [cod] field will go into that file, as normal. st7/ dat1 segment byte at: 10 'data' ds.w com1 segment common 'data' .lab1 ds.w 4 com1 segment common 'data' .lab2 ds.w 2 com2 segment common 'data' .lab3 ds.w com2 segment common 'data' .lab4 ds.w 2 dat2 segment 'data' .lab5 ds.w 2 end com1 segment byte at: 10 'data' com1 segment common 'data' ... com1 segment common 'data' ...
3 st7 assembler st7 assembler linker 26/92 UM0144 if one class is introduced with a [cod] field of 1 , though, then all code produced under that class is sent instead to a file prog_1.cod . the code produced under the other classes is sent on as usual to prog.cod . using this scheme, you can do bank switching schemes quickly and directly, even when multiple eproms share the same addressing space. simply allocate each eprom class of its own, and introduce each class with a different [cod] field. this will result in the linker collating eprom's contents into a different .cod file for you to obsend independently. for example: 3.4.2 copying code it sometimes happens that you need to copy a block of code from eprom to ram. this presents some difficulties because all labels in that piece of code must have the ram addresses, otherwise any absolute address references in the code will point back to the eprom copy. in this case, it helps to specify a class for execution , and use a different class for storage , as in the following example: the code starting from ' label1 ' will be stored in the ' code ' class as usual, but all the labels in that special segment will be given addresses in the ' ram ' class, and memory will also be reserved in the ram class for the contents of the special segment. 3.5 macros macros are assembly-time subroutines . when you call an execution-time subroutine you have to go through several time-consuming steps: loading registers with the arguments for the subroutine, having saved and emptied out the old contents of the registers if necessary, pushing registers used by the subroutine (with its attendant stack activity) and returning from the subroutine (more stack activity) then popping off preserved registers and continuing. although macros don't get rid of all these problems, they can go a long way toward making your program execute faster than using subroutines?at a cost. the cost is program size. each time you invoke a macro to do a particular job, the whole macro assembly code is inserted into your source code . this means there is no stacking for return addresses?your program just runs straight into the code; but it's obviously not feasible to do this for subroutines above certain size. segment byte at:8000-bfff 'eprom1' 1 segment byte at:8000-bfff 'eprom2' 2 segment byte at: 0 'code' segment byte at: 8000 'ram' segment 'ram>code' label1: nop
st7 assembler linker 3 st7 assembler UM0144 27/92 the true use of macros is in small snippets of code that you use repeatedly? perhaps with different arguments?which can be formalized into a 'template' for the macros' definition. 3.5.1 defining macros macros are defined using three directives: macro, mend and local . the format is: macro [parameter-1][, parameter-2 ...] [local] [, label-name ...]] mend for example: the piece of code of the example might be called by: add16 index,offset,index which would add the following statements to the source code at that point: ld a,index adc a,offset ld index.x,a note that the formal parameters given in the definition have been replaced by the actual parameters given on the calling line . these new parameters may be expressions or strings as well as label names or constants. because they may be complex expressions, they are bracketed when there is any extra numeric activity; this is to make sure they come out with the precedence correctly parsed. macros do not need to have any parameters. you may leave the macro argument field blank (and, in this case, give no parameters on the calling line). there is one further problem: because a macro may be called several times in the same module, any labels defined in the macro will be duplicated. the local directive gets around this problem: add16 macro first,second,result ld a,first adc a,second ld result,a mend
3 st7 assembler st7 assembler linker 28/92 UM0144 for example: this macro creates the code for a loop to await io port at $c000 to go low. without the local directive, the label ' loop ' would be defined as many times as the macro is called, producing syntax errors at assembly time. because it's been declared local at the start of the macro definition, the assembler takes care of it. wherever it sees the label ' loop ' inside the macro, it changes the name ' loop ' to ' locxxxx ' where xxxx is a hex number from 0000 to ffff . each time a local label is used, xxxx is incremented. so, the first time the getio macro is called, ' loop ' is actually defined as ' loc0 ', the second time as ' loc1 ' and so on, each of these being a unique reference name. the reference to ' loop ' in the 'if' statement is also detected and changed to the appropriate new local variable. the directives in ta b l e 1 0 are very useful, in conjunction with macros: 3.5.2 parameter substitution the assembler looks for macro parameters after every space character. if you want to embed a parameter, for example, in the middle of a label, you must precede the parameter name with an ampersand ' & ' character, to make the parameter visible to the preprocessor. for example, if we have a parameter called ' param '., dc.w param it works as expected, but the ampersand is necessary on: label¶m:nop label¶m&_¶m:nop otherwise ' labelparam ' would be left as a valid label name; if the macro parameter ' param ' had the value ' 5 ', then ' label5 ' and ' label5_5 ' would be created. getio macro local loop loop ld a,$c000 jra loop mend table 10. some useful directives directive usage #ifb to implement macro optional parameters. #ifdef to test if a parameter is defined. #iflab to test if a parameter is a label. #ifidn to compare a parameter to a given string.
st7 assembler linker 3 st7 assembler UM0144 29/92 3.6 conditional assembly conditional assembly is used to choose to ignore or select whole areas of assembler code. this is useful for generating different versions of a program by setting a particular variable in an include file that forces the use of certain pieces of code instead of others. 3.6.1 #if, #else and #endif directives there are three main directives used to perform conditional assembly, as shown in ta bl e 1 1 . the condition given with the ' #if ' may take the form of any numeric expression. the rule for deciding whether it resolves to 'true' or 'false' is simple: if it has a zero value then it's false, else it's true. these directives should not start at column 1 of line, reserved for labels. for example: #if {count eq 1} %out 'true' #else %out 'false' #endif this sequence would print ' true ' if the label ' count ' did equal 1, and ? false ? if it didn't. for example: #if {count gt 1} %out count more than one #if {count gt 2} %out ...and more of two ! #else %out ...but not more than two! #endif #else %out count not more than one #endif table 11. summary of assembly directives directive usage #if marks the start of the conditional and decides whether the following zone will be assembled or not. #else optionally reserves the condition of the previous #if for the following zone. #endif marks the end of the previous #if's.
3 st7 assembler st7 assembler linker 30/92 UM0144 as you can see, conditionals may be nested?the #else and #endif directive are assumed to apply to the most recent unterminated #if . other special #if directives are available as shown in ta b l e 1 2 . 3.7 running the assembler 3.7.1 command line the assembler needs the following arguments: asm , , [;] if any or all the arguments are left out of the command line, you'll be prompted for the remaining arguments. for example: asm stmicroelectronics - assembler - rel. 4.44 file to assemble: game in the example above, no parameters were given on the command line, so all the parameters were prompted for. the parameter assumes a default suffix ".asm" . for example, if you type ' game ' then ' game.asm ' is the actual filename used. the listing file is the file to which the assembly report is sent if selected. the default filename (which is displayed in square brackets), is made from the path and base-name of the file to assemble. the default filename suffix for the assembly report file is " .lst ". for instance, if you type ' game ', then ' game.lst ' is the actual filename used. note that unless the assembler is told to create either a pass-1 or pass-2 complete listing by the options argument, the listing file will not be created. table 12. special #if directives directive usage #if1 and #if2 require no conditional argument. if the appropriate pass is. being assembled, the condition is considered ' true '; for instance #if1 will be considered true while the assembler is in first pass, #if2 while in the second pass. #ifdef checks for label definition. #ifb checks for empty argument (i.e., empty, or containing spaces / tabs), useful for testing macro parameter existence. #iff (if false) is similar to #if, but checks the negation of the condition argument. #ifidn tests for string equality between two arguments separated by a space. this is useful for testing macro parameters against fixed strings. #iflab checks if the argument is a predefined label.
st7 assembler linker 3 st7 assembler UM0144 31/92 3.7.2 about options options are always preceded with a minus sign '-'. upper and lower cases are accepted to define options. supported options are listed in ta b l e 1 3 . sym option li option table 13. command line options option function -sym enable symbol table listing -li -li= enable pass-2 listing enable listing and specify name of .lst file -obj= specify .obj file -fi= specify 'final' listing mode -d <1> <2> #define <1> <2> -i specify paths for included or loaded files -m output make rule -pa enable pass-1 listing -np disable phase errors description: this option allows the generation of a symbol table. format: asm -sym example: asm prog -sym the output is the file prog.sym description: request to generate a complete listing file. use the option -li= to specify the pathname for the generated .lst file. format: asm -li or asm -li= example: asm prog -li the output is the file prog.lst in the current directory asm prog -li=obj\prog the output is the file obj\prog.lst
3 st7 assembler st7 assembler linker 32/92 UM0144 obj option fi option note: when assembling in ' -fi ' mode, the assembler uses the map file produced by the linker, and no object files are generated. note: when using the option -fi=.map , the assembler step may fail under certain circumstances: if there are empty segments (error 73). to avoid this, comment out any empty segments. if you try to assemble a file that has not been used to produce the .map file (error 73). some extern labels are never used (warning 80). to avoid this, comment the unused extern labels out. description: you can specify the pathname for the generated .obj file, using the following option: format: asm -obj= example: asm prog -obj=obj\prog forces the assembler to generate the object file obj\prog.obj . description: one side effect of using a linker is that all modules are assembled separately, leaving inter modules' cross-references to be fixed up by the linker. as a result the assembler listing file set all unresolved references to 0, and displays a warning character. the ' -fi ' option enables you to perform an absolute patch on the desired listing. therefore, you must have produced a listing file ( .lst ) and linked your application to compute relocations and produce a .cod file and a map file. when you want a full listing to be generated, you must not have made any edits since the last link (otherwise the named map-file would be 'out of date' for the module being assembled). this is not usually a problem since full listings are only needed after all the code has been completed. -fi automatically selects a complete listing. format: asm -fi=.map the output .lst contains the absolute patches. example: asm -li ex1 (produces ex1.lst ) asm -li ex2 (produces ex2.lst ) lyn ex1+ex2,ex (produces ex.map , ex.cod ) (see chapter : linker on page 35) asm ex1 -fi=ex.map (produces new ex1.lst ) asm ex2 -fi=ex.map (produces new ex2.lst )
st7 assembler linker 3 st7 assembler UM0144 33/92 d option note: if you specify multiple -d switches, they should always be separated by a space. i option description: the -d option allows you to specify a string that is to be replaced by another during the assembly. a blank space or = is required between the string to be replaced and the replacement string. for example -d 2 is the same as -d =2 . it is possible to specify only one argument ( -d ). in which case, is replaced with 1. this is extremely useful for changing the assembly of a module using #if directives, because you can change the value of the #if tests from the assembler's command line. it means that you can run the assembler with different -d switches on the same source file, to produce different codes. format: asm -d or asm -d = or asm -d example: asm ex1 -d eprom 2 -d ram 3 asm ex1 -d eprom=2 -d ram=3 in both cases the string eprom is replaced with 2 . the string ram is replaced with 3 . asm ex1 -d eprom in this case eprom is replaced with 1 . description: the -i option is used to specify the list of search paths for files that are included (with #include) or loaded (with #load). the different paths can be separated by the ; character and the path list must be enclosed within double quotes. you can also enter multiple include paths by using the - i option more than once and separating each with a blank space. the current working directory is always searched first. after that, the st7 assembler searches directories in the same order as they were specified (from left to right) in the command line. format: asm -i=";;...;" call or asm -i="" -i=""... -i="" call example: asm -i="include;include2" call or asm -i="include" -i="include2" call
3 st7 assembler st7 assembler linker 34/92 UM0144 m option pa option np option description: the -m option tells the st7 assembler to output a rule suitable for make, describing the dependencies to make an object file. for a given source file, the st7 assembler outputs one make rule whose target is the object file name for that source file and whose dependencies are all the included (#include) source files and loaded (#load) binary files it uses. the rule is printed on the standard output. format: -m example: asm -i="include;include2" -m call the output appears on the screen as the rule: call.obj: call.asm include\map.inc include2\map2.inc include\map3.inc include\code.bin description: request to generate a pass-1 listing. in this listing internal forward references are not yet known. they are marked as undefined with a 'u' in the listing file. format: asm -pa example: asm file1 -pa the output file is file1.lst description: this option disables the error generation. format: asm -np example: asm file1 -np
st7 assembler linker 4 linker UM0144 35/92 4 linker 4.1 what the linker does after having separately assembled all the component modules in your program, the next step is to link them together into a .cod file which can then be sent on to its final destination using obsend. this linking process is not just as a simple concatenation of the object modules. it resolves all the external references. if a referenced label is not defined as public , an error is detected. it also checks the type of relocation to do, places the segment according to your mapping, and checks if any of them is overrun. 4.2 invoking the linker 4.3 command line the linker needs the following arguments: lyn <.obj file>[+<.obj file>...], [<.cod file>],[][+...] if all or any arguments are left out of the command line, you'll be prompted. for example: lyn stmicroelectronics - linker - rel 3.00 .obj files: begin .cod file [begin.cod]: begin libraries: the .obj files are simply a list of all the object files that form your program. the .obj suffix may be left out, and if more than one is specified they should be separated by ' + ' characters, for example game+scores+keys would tell the linker to link ' game.obj ', ' scores.obj ' and ' key.obj '. object file path names should not include ' - ' or ' ; ' characters. character ' . ' should be avoided, except for suffixes. the .cod file has a default name formed of the first object file's name with forced suffix of ' .cod '. this will be the name of the file produced at the end of the link session. it contains all the information from the link session in a special format: however, obsend must be used on the .cod file before it is ready to use. if the default filename is not what you want, the filename given at the prompt is used instead. the suffix will be forced to .cod if left blank. the default is selected by leaving this argument blank at the command line, or pressing at the prompt. the ' libraries ' prompt asks for a list of library files generated by the lib utility that should be searched in case of finding unresolved external references. the format for giving multiple libraries is the same as for the .obj list, except the suffix .lib is assumed. some examples: linking together the modules game.obj , scores.obj , key.obj , game1.obj, game2.obj and game3.obj without using any libraries and generating a .cod file named game.cod , requires the following command line: lyn game+scores+keys+game1+game2+game3;
4 linker st7 assembler linker 36/92 UM0144 linking the same modules in the same environment, but generating a .cod file named prog.cod requires: lyn game+scores+keys+game1+game2+game3,prog; 4.3.1 response files response files are text files that replace the command line to generate the arguments required. although they can be used on the assembler and linker, it only really makes sense to use them on the linker. the command line given with the name of the program to execute (here lyn ) can only take up to 128 characters as its argument. for most programs this is fine, but the linker allows up to128 modules to be linked in one run; all their names have to be declared to the linker in its first argument. this is where response files come in? they allow you to redirect the command line parser to a file instead of expecting arguments to come from the command line or the keyboard. a response file is invoked by giving an ? @ ? sign and a filename in response to the first argument you want to come from the response file. the filename is assumed to have a suffix ' .rsp ' if none is supplied. repeating our example used as earlier, but this time with a response file called game.rsp : lyn @game.rsp is all that needs to be typed, and the file game.rsp must contain: game+scores+keys+ game1+ game2+game3 prog which echoes what would have been typed at the keyboard. if the response file ends prematurely, the remaining arguments are prompted for at the keyboard. in very large session, the .obj files argument won't fit on one line: it can be continued to the next by ending the last .obj file on the first line with a ' + '. note that when using response files, there must be at least two carriage returns at the end of the file. 4.4 linking in detail 4.4.1 publics and externs all labels declared external in the modules being linked together must have a corresponding public definition in another module. if it doesn't, it may be an error. similarly, there must only be one public definition of a given label. the bulk of the linker's job is filling those relative or external blanks left by the assembler in the .obj files; to a lesser extent, it also handles special functions such as date or skip directives. equally important, it has to collate together and allocate addresses to segments.
st7 assembler linker 4 linker UM0144 37/92 4.4.2 segments in the linker a typical system may look like the diagram alongside: a good candidate for four different segments, perhaps named 'ram0', 'ram1', 'eprom' and 'rom'. if the reset and interrupt vectors live at the end of the map, perhaps from ffee-ffff then we might mark a fifth segment called 'vectors' at those addresses and truncate 'rom' to end at ffed; that way the linker will warn us if 'rom' has so much code in it that it overflows into where the vectors live. these classes would be introduced as follows: segment byte at: 0-ff'ram0' segment byte at: 100-027f'ram1' segment byte at: 8000-bfff'eprom' segment byte at: c000-ffdf'rom' segment byte at: ffe0-ffff'vectors' after their full introduction that needs only be done once in the whole program, the rest of the program can refer to the classes just by giving the class names in quotes, for example: if this example followed immediately after the class instruction the ' xtemp ' label would be given the value 0 , time would be given 2 and hex c000 . if, however, the code was several modules away from the introduction with segments of the classes ' ram0 ' or ' rom ', then the value allocated to all the labels will depend on how much space was used up by those modules. the linker takes care of all this allocation. this is the way the linker handles the problems of relocatability; keep in mind that this link system is going to have to handle compiled code from high level languages and you'll perhaps begin to understand why things have to be generalized so much. so far the segments we've looked at have had no field, or, more accurately, they all had a null name field. you can ensure that related segments of the same class, perhaps scattered all over your modules with segments of the same class are collated together in a contiguous area of the class memory by giving them the same name. segment 'ram0' xtemp ds.w ; temp storage for x register time ds.b ; timer count index segment 'rom' hex ld a,#1 add a,#10 nop
4 linker st7 assembler linker 38/92 UM0144 for example: this complex sequence of segments shows now instances of the class ' ram1 ' being used with a segment name of ' grafix '. because the first instance of the class ' ram1 ' had the name ' grafix ' the two ' grafix ' ram1 segments are placed in memory first followed by the null-name ram1 segment (which defines ' field_buf '). note this is not the order of the segments in the code?segments with the same name are collated together (even from separate .obj files), and the lumps of segments of the same name are put into memory in the order that the names are found in the .obj files. as explained in section on page 25, if x is your cod file suffix when introducing a class, all code for that code is sent into a new cod-file named file_x.cod , where file is the name of the first cod file, and x is the cod-file suffix ( 1-9 ). 4.4.3 symbol files at the end of a successful link, one or more .obj files will have been combined into a single .cod file. a .map file will have been produced, containing textual information about the segments, classes and external labels used by the .obj module(s). finally a compact .sym file is generated, containing all public symbols found in the link with their final values. the linker supports a special feature?you can link in .sym files from other link sessions. this means that with big programs, you cannot only partition your code at assembler level, but divide the code up into 'lumps' which are linked and loaded separately, but have access to each other's label as externs . you can 'link in' a symbol table simply by giving its name with the suffix .sym . always give symbol tables at the start of the object file list. obj file example: lyn prog1.sym+prog2,vectors,irq; once this is done, all the public symbols from prog1.sym are now available as publics to prog2.obj , vectors.obj and irq.obj . because changes in one link will not automatically update references to the changed link code in other links, it's necessary when using this technique to 'fix' each link in an area of memory, and have a 'jump table' at the top of each area. this means that all 'function' addresses are permanently fixed as jump table offset, and changes to each link will result in automatic redirection of the jump targets to the new start of grafix segment byte at: 100-027f 'ram1' cursor_buf ds.b 64 ; buffer for map under cursor segment byte at: 8000-bfff 'rom' show_page nop segment 'ram1' field-buf ds.b {{256 mult 256}/8} segment 'rom' dump_buf ld a,field_buffer grafix segment 'ram1' cursor_temp ds.b 64
st7 assembler linker 4 linker UM0144 39/92 each routine. put another way, each link must have entry fixed points to all its routine, otherwise re-linking one 'lump' of a program could make references to its addresses in other modules out of date. 4.5 the linker in more detail 4.5.1 the composition of the .obj files the .obj files produced by the assembler contain an enormous amount of overhead, mostly as coded expressions describing exactly what needs to go into the 'blank spaces' the assembler has been so liberal with. the linker contains a full arithmetic parser for 'working out' complex expressions that include external labels: this means (unlike most other assemblers) there are few restrictions on where external labels may appear. the assembler also includes line-number information with the .obj file, connecting each piece of generated object code with a line number from a given source file. obj files also contain 'special' markers for handling skip and date type directive. 4.5.2 the composition of the .cod files .cod files, on the other hand, contain very little overhead; there are six bytes per segment that describe the start address and length of that segment. besides that, the rest of the code is in its final form. a segment of zero length marks the end of the file. it only remains for obsend to take the code segment by segment and send it on to its destination. 4.5.3 reading a mapfile listing the linker also generates files with the suffix .sym and .map in addition to the .cod file we have already discussed. the .sym file contains a compact symbol table list suitable with the debuggers and simulators. the .map file listing shows three important things: a table of segments with their absolute address, a table of all classes in the program, and a list of all external labels with their true values, modules they were defined in and size. here is an example mapfile , where one of the class, rom , has gone past its limit, overwriting (or more correctly, having part of itself overwritten by) vectors . the [void] on some segments in the segment list says that these segments were not used to create object code, but were used for non-coding-creating tasks such as allocating label values with ds.b etc. the number in straight brackets on the segment as true address list shows how many segments 'into' the module this segment is, i.e., the 1 s t , 2 nd etc. of the given module. the first x-y shows the range of addresses. the def (line) field on the external labels list shows the source code file and line number that his label was defined in. the number at the start of each class list line is the cod-file that the class contents were sent to (default is 0 ).
4 linker st7 assembler linker 40/92 UM0144 segment address list: class list: external label list: the external label list only includes labels that were declared public : labels used internally to the module are not included. this table is most useful for debugging purposes, since the values of labels are likely to be relocated between assemblies. the labels are given in first-character-alphabetic order. prog [1] 10- 86 0- 6 ?ram0' [void] prog [2] 88- 278 100- 138 'ram1' [void] main [1] 8- 563 8000- 875b 'eprom' prog [4] 282- 889 c000- c508 'rom' main [2] 568- 1456 c509- f578 'rom' monitor [1] 8- 446 f579- fff9 'rom' monitor [2] 448- 467 ffee- ffff 'vectors? 0 ?ram0' byte from 0 to 78 (lim ff) 45% d 0 ?ram1' byte from 100 to 138 (lim 27f) 50% d 0 ?eprom' byte from 8000 to 875b (lim bfff) 21% c 0 ?rom' byte from c000 to fff9 (lim ffdf) c*overrun* 0 ?vectors' byte from ffee to ffff (lim ffff) 100% d symbol name value size def(line) char 64 byte game.obj(10) char1 66 byte game.obj(11) label abcd word game.obj(25) 3 labels
st7 assembler linker 5 obsend UM0144 41/92 5 obsend 5.1 what obsend does for you after your program has been assembled and linked to form a ' .cod ' file it needs to be sent on to the place where it will be executed. right now, your code is just stored as a file on a disk where the target system can't get at it. obsend is a general purpose utility for .cod files in various ways using various formats. 5.2 invoking obsend obsend follows the same standard formats as the rest of the assembler / linker; arguments can be given from the command line, keyboard or response file. the general syntax is: obsend ,[,], where is the name of the .cod file to be formatted (default extension .cod ). if the filename is not given on the command line, you're prompted at the keyboard with: obsend stmicroelectronics - obsend - rel. .2.00 file to send: test destination type (ile,ideo): f final object code filename [test.fin]: test.s19 object format =straight binary, ..., st rec <2>, st rec <4>: s 5.2.1 destination type can be " f " (file) or " v " (video). only a single character is required. 5.2.2 destination arguments when the destination type is " f " (file) the argument tells obsend where to send the code. the default suffix ' .fin ' is assumed if none is given. for example: obsend test,f,image.s19,s the command generates the file ' image.s19 ' containing the code from ' test.cod ', in s- record s format. when the destination code is " v " (video), this field is void.
5 obsend st7 assembler linker 42/92 UM0144 5.2.3 format definitions specifies the output format. output format options are listed in ta bl e 1 4 . 5.2.4 straight binary format = this is the simplest of the formats. it's nothing but a bit-for-bit copy of the original file. this the usual mode for sending to the eprom emulators, etc., and is the default if no format argument is given. note: when the destination is the screen (the destination code is " v "), don't use this format; otherwise you will only get weird control codes. = this is the ?filled? straight binary format where gaps between adjacent segments are filled with $ff . 5.2.5 intel hex format = i this format is very much more complex. intel hex bears similarities to s-record that we'll be looking at later. let's look at a line of the intel hex format in detail: :10190000ffffffffffc00064ffc0006462856285e0 10 number of data bytes (16 in decimal) 1900 address 00 record type ... data bytes e0 checksum table 14. output formats output format straight binary, i.e., a bit for bit image i intel hex i32 intel hex with 32-byte data per line ix intel hex extended s motorola s-record (1 byte per address, e.g. st7) x motorola s-record extended with symbol file 2 st s-record 2 (2 bytes per address, e.g. d950) 4 st s-record 4 (4 bytes per address, e.g. st18932 program space) f 'filled' straight binary format g gp industrial binary format
st7 assembler linker 5 obsend UM0144 43/92 the first thing to note is that every thing is in printable ascii. eight bit numbers are converted into two-characters hexadecimal representation. each line begins with an ascii ' : ' ( $3a ) character. the next two characters form a byte that declares how many data bytes follow in the data byte section little further along. the next four characters form a 16-bit high-byte first number that specifies the address for the first byte of this data; the rest follows on sequentially. the next two characters are the record type for this line: 00 is a data line, and 01 signals eof. the following characters until the last two are up the 16 data bytes for this line and, the last two are a checksum for the line, calculated by starting with $00 subtracting the real value of all characters sent after the ' : ' until the checksum itself. 'real value' means that for example, the two characters 3 and 0 should subtract $30 from the checksum, not 51 and 48 . every line ends with a cr-lf combination, $0a and $0d . the last line sent must be an end-of-file line, which is denoted by a line with no data bytes and a record type of 01 instead of 00. giving i32 or i32 instead of intel as the argument uses the same format, but sends 32 bytes of data per line. 5.2.6 motorola s-record format = s this is another complex method for sending data. again it cuts the data into 16-byte 'records' with overhead either sides. s-record come in four types: s0 , known as a header record, s1 and s2 data records with 16 and 24-bit address fields, and s9 and s8 eof records with 16 and 24- bit address fields. note: the convention is to close a s1 16-bit data record with the s9 16-bit eof record, and to close a s2 24-bit data record with the s8 24-bit eof record. s10d0010e0006285e000628562856d s1 record type 0d number of bytes left, address, data and checksum (13 in decimal) 0010 address .... data bytes 6d checksum the first two characters define the record type: s0 , s1 , s2 , s8 or s9 . the next two characters form a hexadecimal representation of the numbers of bytes left in the record (i.e., numbers of characters /2) this count must include the checksum and addresses bytes that follow. the address field is four characters wide in s0 , s1 , s9 and six characters wide in s2 and s8 . the most significant character always comes first. obsend will always use s1 type records wherever possible (i.e., when the address is less than $10000 ) and use s2 type data records where it has to (i.e., address > $ffff ). up to 16 data bytes then follow, with the checksum appended on the end. the checksum is calculated by starting with $ff and subtracting the 'real value' of all bytes sent from and
5 obsend st7 assembler linker 44/92 UM0144 including the byte count field until the checksum itself. in this context, 'real value' means the value of the byte before it is expanded into two ascii characters. the record is concluded by a cr-lf combination $0a , $0d . the s0 , s8 and s9 (i.e., header and eof) records are always the same: s00600004844521b and: s804000000fb s9030000fc a complete example of s-record transmission may look like: s00600004844521b s113001aff120094ff130094d08aff390094ff1250 s20801c004ffc0000073 = x the extended s-record format , selected by format x, sends code as described above, except that after the s9 , it sends a list of sx records, one after the other, in the format: sx 0000 label where 0000 are four ascii zeroes, and label is five ascii characters. there are two spaces after the sx and one space after the 0000 . 0000 represents the hexadecimal value of the label. label may extend to 31 characters, and end with a carriage return. 5.2.7 st 2 and st 4 s-record formats = 2 = 4 these are industrial formats defined for specific needs. 2: this format allows to specify 2-byte words for one address. 4: this format allows to specify 4-byte words for one address. 5.2.8 gp binary = g this format is simple. it has a 16-byte count at the beginning low-byte first, calculated by starting at 0 , and adding the value of each byte until the end of the data is reached. if there are any 'gaps' in your code, obsend will fill them in with $ff , and adjust the checksum accordingly. after that four bytes of header information, the data follows in one big block.
st7 assembler linker 6 librarian UM0144 45/92 6 librarian 6.1 overview if you do a lot of work on similar boards especially those with the same processor, it makes a great deal of sense to reuse lumps of code you've already written to do the same task in a different program. at the simplest level, you could just copy the source code as a block of text into the new program. this works fine, but has a subtle disadvantage: if you update the subroutine, you have to hunt around all the usages of it, performing the update on each. to get around this problem, many people have the source for common routines in one place, and link the .obj module with each program needing routine. then you only need to update the source code once, reassemble it to get a new .obj file, then link again all the users of the routine, who will now have the new .obj file. while this scheme works well, it generates some problems of its own. for example, each routine needs its own .obj file. by nature, these common routines tend to be small, so you end up giving dozens of extra .obj modules to the linker, and having the .obj modules scattered around your hard disk. the base concept of a librarian is to combine all these small, useful .obj modules into one large .lib library file. you could then tell the linker about the library, and it would take care of sorting out which .obj modules to pull into link. it would know which ones to pull by the fact that the main code being linked would have undefined externals, for example, to call the missing library routines. the librarian simply takes each undefined external in turn, and checks it against all the modules in the library. if any of the modules declares a public of the same name, it knows you need that .obj module and it includes it automatically. 6.2 invoking the librarian the librarian is called lib , and takes one command line argument that is the name of the library to operate on. if not given, you'll be prompted for it. lib [library name] .lib is added if the suffix is left off. if the library you indicate doesn't exist, lib asks you if it's a new library. for example: lib lib1 stmicroelectronics - librarian - rel 1.00 couldn't open library file 'lib1.lib' is it a new file? (y/n): y if the answer is ' n ', lib aborts. if the library exists, lib prints up a report on the library. library lib1.lib is 2k long. 16/1024 public labels used in 2/128 modules. next you're faced with the main prompt: lib1.lib: operation ( for help):
6 librarian st7 assembler linker 46/92 UM0144 pressing enter gives you access to the options shown in table 15 . 6.3 adding modules to a library typing for example: +user1\board would look for a file, called user1\board.obj , and add it to the library. if lib can't find the named file, lib reports the fact and returns to the operations prompt. else lib issues the following message: adding new board.obj ... 15 labels added done. if the library already contained a file board.obj , it would prompt you with: board.obj already in library lib1.lib, replace with board.obj (y/n): responding with ' n ? returns you to the operations prompt, while ' y ' first removes the old board.obj then continues as above. 6.4 deleting modules from a library this is done by, for example: -board if lib cannot find board.obj in the current library, it reports an error and aborts back to the operation prompt. if it can find it, it makes sure you know what you are doing with: board.obj to be deleted from library lib1.lib: are you sure (y/n): n ? aborts to operation prompt. 'y' continues, reporting: removing old board.obj ... done. table 15. library file options operation description +filename add/update object module to/in library -filename delete object module from library !filename update object module in library *filename copy object module to separate file from library ? list contents of library x exit to dos
st7 assembler linker 6 librarian UM0144 47/92 6.5 copying modules from a library to make a copy of a .obj module located in a library back to your hard disk, use, for example: *board this will check the existence of board.obj in the current library, if not it'll report the failure and abort the operation prompt. if it does find it, it invites you to give it the name of the hard disk file to create to contain the copy of the .obj module. copy into .obj file [board.obj]: if you type < enter >, it'll select the original name of the object module as the copy's name. otherwise, give it a path spec. if the file you give already exists, lib says: file board.obj already exists; overwrite? (y/n): again, responding ' n ' aborts to the operations prompt, while ' y ' does the copy with the message: copying board.obj to disk... done. 6.6 getting details in your library the last operation: ? causes lib to print out details on the current library. library lib1.lib is 2k long 16/1024 publics labels used on 2/128 modules 0: z1.obj (z1.asm) length 2de 1: board.obj (board.asm) length 7fff the name in brackets is the source module from which the named object module was assembled.
st7 assembler linker 48/92 UM0144 appendix a assembler directives a.1 introduction each directive has been given a new section to itself, and an entry in the index. the name of the directive, which will always appear in the second field is given in the heading at the top of the section. next there is a line showing arguments allowed (if any) for this directive. the penultimate section describes the action of the directive and the format and nature of the argument specified in the previous section, and the last section gives one or more example of the directive in use. there is a 'see also' cross reference at the bottom of the page. all the directives must be placed in the second, opcode, field, with any arguments one tab away in the argument field. a.2 .bell purpose: ring bell on console. format: . bell description: this directive simply rings the bell at the console; it can be used to signal the end of pass-1 or pass-2 with #if1 or #if2. this directive does not generate assembly code or data. example: .bell see also:
st7 assembler linker UM0144 49/92 a.3 byte a.4 bytes purpose: define byte in object code. format: byte ,[,...] description: this directive forces the byte(s) in its argument list into the object code at the current address. the argument may be composed of complex expressions, which may even include external labels. if the argument was an expression and had a value greater than 255 then the lower 8 bits of the expression are used and no errors are generated. string argument(s) must be surrounded by double quotes: theses are translated into ascii and processed byte by byte. it's generally used for defining data tables. synonymous with string and dc.b. example: byte 1,2,3 ; generates 01,02,03 byte ?hello? ; generates 48,45,4c,4c,4f byte ?hello?,0 ; generates 48,45,4c,4c,4f,0 0 see also: dc.b, string, word, long, dc.w, dc.l purpose: label type definition where type = byte. format: bytes description: when a label is defined, 4 separate attributes are defined with it: scope (internally or externally defined), value (actual numerical value of the label), relativity (abso- lute or relative), and length, (byte, word and long). all of these attributes, except length, are defined explicitly before or at the defini- tion. you can force the label to be a certain length by giving a dot suffix?eg. 'label.b' forces it to be byte length. you may also define a default state for label length: labels are created to this length unless otherwise forced with a suffix. the default is set to word at the start of the assembly, but may be changed by bytes, words or longs to the appropriate length. example: see also: longs, words bytes lab1 equ 5 ; byte length for lab1
st7 assembler linker 50/92 UM0144 a.5 cequ a.6 .ctrl a.7 date purpose: equate pre-existing label to expression. format: label cequ description: this directive is similar to equ, but allows to change the label's value. used in macros and as counter for repeat / until. example: see also: equ, repeat, until purpose: send control codes to the printer. format: .ctrl [,]... description: this directive is used to send printing and non printing control codes to the selected listing device. it's intended for sending control codes to embolden or underline, etc. areas of listing on a printer. the arguments are sent to the listing device if the listing is currently selected. this directive does not generate assembly code or data. example: see also: .list, .nolist, .bell purpose: define 12-byte ascii date into object code. format: date description: this directive leaves a message for the linker to place the date of the link in a 12-byte block the assembler leaves spare at the position of the date directive. this means that every link will leave its date in the object code, allowing automatic version con- trol. the date takes the form (in ascii) dd_mmm_yyyy where character '_' repre- sents a space; for example 18 jul. 1988. the date is left for the linker to fill instead of the assembler since the source code module containing the date directive may not be reassembled after every editing session and it would be possible to lose track. example: see also: lab1 cequ {lab1+1} ; inc lab1 .ctrl 27,18 date
st7 assembler linker UM0144 51/92 a.8 dc.b a.9 dc.w purpose: define byte(s) in object code. format: dc.b ,[,] description: this directive forces the byte(s) in its argument list into the object code at the cur- rent address. the argument may be composed of complex expressions, which may even include external labels. if the argument was an expression and had a value greater than 255 then the lower 8 bits of the expression are used and no errors are generated. string argument(s) must be surrounded by double-quotes: these are translated into ascii and processed byte by byte. it's generally used for defining data tables. synonymous with byte and string . example: purpose: define word(s) in object code. format: dc.w[, ...] description: this directive forces the word(s) in its argument list into the object code at the current address. the arguments may be composed of complex expressions, which may even include external labels. if the argument was an expression and had a value greater than ffff then the lower 16 bits of the expression are used and no errors are generated. dc.w sends the words with the most significant byte first. it's generally used for defining data tables. synonymous with word , except that dc.w places the words in high / low order. example: see also: dc.b, byte, string, word, long, dc.l dc.b 1,2,3 ; generates 01,02,03 dc.b ?hello? ; generates 48,45,4c,4c,4f dc.b ?hello?,0 ; generates 48,45,4c,4c,4f,00 dc.w 1,2,3,4,$1234 ;0001,0002,0003,0004,1234
st7 assembler linker 52/92 UM0144 a.10 dc.l a.11 #define purpose: define long word(s) in object code. format: dc.l [,...] description: this directive forces the long word(s) argument list into the object code at the current address. the arguments may be composed of complex expressions, which may even include external labels. if the argument was an expression and had a value greater than ffffffff then the 32 bits of the expression are used and no errors are generated. dc.l sends the words with the most significant byte first. it's generally used for defining data tables. synonymous with long , except that dc.l stores the long-words in high / low order. example: see also: dc.b, dc.w, byte, string, word, long purpose: define manifest constant. format: #define description: the benefits of using labels in assembler level programming are obvious and well known. sometimes, though, values other than the straight numerics allowed in labels are used repeatedly in programs and are ideal candidates for special labelling. the #define directive allows you to define special labels called 'manifest con- stants'. these are basically labels that contain strings instead of numeric constants. during the assembly, wherever a manifest id is found in the source code, it is replaced by its real argument before the assembly proceeds. the #define is not the definition of a label, so a space must precede the declaration. the number of defines that the assembler can manage is limited to 4096. however, this depends on the number of characters in the statements. depending on their length, you may reach this limit sooner. example: see also: dc.l 1,$12345678 ; 0000,0001,1234,5678 long 1,$12345678 ; 0100,0000,7856,3421 #define value 5 ld a,#value ; ld a,#5
st7 assembler linker UM0144 53/92 a.12 ds.b purpose: define byte space in object code. format: ds.b [optional number of bytes] description: this directive is used to 'space out' label definitions. for example let's say we need a set of byte-sized temporary storage locations to be defined in ram, starting at address $4000. we could write: segment byte at 4000 'ram' temp1 equ $4000 temp2 equ $4001 which would work fine, however, we recommend you to write: segment byte at 4000 'ram' temp1 ds.b temp2 ds.b which does the same job. the advantage is that the pc increments automatically. there are two other types of ds instructions available for doing word and long length storage areas: ds.w and ds.l. note that the areas in question are not initial- ized to any value; it's merely a way of allocating values to labels. the optional argument specifies how many bytes to allocate; the default is 1. because no code is generated to fill the space, you are not allowed to use ds.b in segments containing code, only for segments with data definitions. example: see also: ds.w, ds.l labl ds.b
st7 assembler linker 54/92 UM0144 a.13 ds.w purpose: define word space in object code. format: ds.w [optional number of words] description: this directive is used to 'space out' label definitions. for example let's say we need a set of word-sized temporary storage locations to be defined in ram, starting at address $4000. we could write: segment byte at 4000 'ram' temp1 equ $4000 temp2 equ $4002 which would work fine, however, we recommend you to write: segment byte at 4000 'ram' temp1 ds.w temp2 ds.w which does the same job. the advantage is that the pc increments automatically. there are two other types of ds instructions available for doing byte and long length storage areas: ds.b and ds.l. note that the areas in question are not initial- ized to any value; it's merely a way of allocating values to labels. the optional argument specifies how many bytes to allocate; the default is 1. because no code is generated to fill the space, you are not allowed to use ds.w in segments containing code, only for segments with data definitions. example: see also: ds.b, ds.l labl ds.w
st7 assembler linker UM0144 55/92 a.14 ds.l a.15 end purpose: define long space in object code. format: ds.l [optional number of long words] description: this directive is used to 'space out' label definitions. for example let's say we need a set of long-word-sized temporary storage loca tions to be defined in ram, starting at address $4000. we could write: segment byte at 4000 'ram' temp1 equ $4000 temp2 equ $4004 which would work fine, however, we recommend you to write: segment byte at 4000 'ram' temp1 ds.l temp2 ds.l which does the same job. the advantage is that the pc increments automatically. there are two other types of ds instructions available for doing byte and word length storage areas: ds.b and ds.w. note that the areas in question are not initial- ized to any value; it's merely a way of allocating values to labels. the optional argument specifies how many bytes to allocate; the default is 1. because no code is generated to fill the space, you are not allowed to use ds.l in segments containing code, only for segments with data definitions. example: see also: ds.b, ds.w purpose: end of source code. format: end description: this directive marks the end of the assembly on the main source code file. if no end directive is supplied in a source-code file then an illegal eof error will be generated by the assembler. include files do not require an end directive. example: see also: labl ds.l end
st7 assembler linker 56/92 UM0144 a.16 equ a.17 extern purpose: equate the label to expression. format: label equ description: most labels created in a program are attached to a source code line that generates object code, and are used as a target for jumps or memory references. the rest are labels used as 'constants', used for example, to hold the io port number for the sys- tem keyboard: a number that will remain constant throughout the program. the equ directive allocates the value, segment type and length to the label field. the value is derived from the result of the expression, the relativity (absolute or seg- ment-relative derived from the most recent segment), the length is byte, word or long, derived from the size default (starts off as word and may be changed by directives bytes , words or longs ). example: see also: purpose: declare external labels. format: extern description: when your program consists of several modules, some modules need to refer to labels that are defined in other modules. since the modules are assembled sepa- rately, it is not until the link stage that all the necessary label values are going to be known. whenever a label appears in an extern directive, a note is made for the linker to resolve the reference. declaring a label external is a way of telling the assembler not to expect the label to be defined in this module, although it will be used. obviously, external labels must be defined in other modules at link stage, so that all the gaps left by the assembler can be filled with the right values. because the labels declared external are not actually defined, the assembler has no way of knowing the length, i.e., (byte, word or long) of the label. therefore, a suffix must be used on each label in an extern directive declaring its type; if the type is undefined, the current default label scope (set by bytes, words, longs direc- tives) is assumed. example: see also: public labl end 5 extern label.w, label1.b, label2.l
st7 assembler linker UM0144 57/92 a.18 #else a.19 #endif purpose: conditional else. format: #else description: forces execution of the statements until the next #endif if the last #if statement was found false or disables execution of the statements until the next #endif if the last #if statement was found true. the #else is optional in #if / #endif structures. in case of nested #else state- ments, a #else refers to the last # if . example: see also: #if, #endif purpose: conditional terminator. format: #endif description: this is the non optional terminator of a #if structure. if there is only one level of #if nesting in force, then the statements after this directive will never be ignored, no matter what the result of the previous #if was. in other words, the #endif ends the capability of the previous #if to suppress assembly. when used in a nested situation it does the same job, but if the last #if / #endif structure was in a block of source suppressed by a previous #if still in force, the whole of the last #if / #endif struc- ture will be ignored no matter what the result of the previous #if was. example: see also: #if, #else #if {1 eq 0} ; ; block a ... not assembled #else ; block b ... assembled #endif #if {count gt 0} ... #endif
st7 assembler linker 58/92 UM0144 a.20 fcs a.21 .form a.22 group purpose: form constant string. format: fcs <"string"> | [ |]... description: this directive works in the same way as the common string directive, except that the last character in any string argument has bit 7 (e.g. msb) forced high. numeric arguments in the same list are left untouched. example: see also: string purpose: set form length of the listing device. format: .form description: the assembler paginates the listing (when selected) with a default of 66 lines per page. this directive changes the page length from the default. this directive does not generate assembly code or data. example: see also: title, subttl, %out, .lall, .xall, .sall, .list,.nolist purpose: name area of source code. format: group description: all source code following a group directive until the next group directive or the end of the file - 'belongs' to the named group. source code not included inside a group is allocated to a special group called 'default'. example: see also: fcs ?allo? ; 41,4c,4c,cf string ?allo? ; 41,4c,4c,4f .form 72 group mainloop
st7 assembler linker UM0144 59/92 a.23 #if a.24 #if1 conditional purpose: start conditional assembly. format: #if description: sometimes it is necessary to have different versions of a program or macro. this can be achieved by completely separate programs / macros, but this solution has the associated problem that changes to any part of the program common to all the versions requires all of them being changed, which can be tedious. conditional assembly offers the solution of controlled 'switching off' assembly of the source code, depending on the value of the numeric expressions. the structure is known as ' if/else/endif ': see the example for the format. the #else statement is optional. if the expression resolves to 0 the expression is assumed to have a 'false' result: the source code between the false #if and the next #endif (or #else if supplied) will not be assembled. if the #else is supplied, the code following the #else will be assembled only if the condition is false. conditionals may be nested up to 15 levels : when nesting them, keep in mind that each #if must have a #endif at its level, and that #endifs and #elses refer to the last unterminated #if . example: see also: #endif, #else, #if1, #if2 purpose: conditional on being in pass #1. format: #if1 description: this directive works just like #if except it has no argument and only evaluates itself as true if the assembler is on its first pass through the source code. can use #else and requires #endif. example: see also: #if2, #else, #if, #endif #if {1 eq 1} %out true #false %out false #endif #if1 %out ?starting assembly? #endif
st7 assembler linker 60/92 UM0144 a.25 #if2 a.26 #ifb purpose: conditional on being in pass #2. format: #if2 description: this directive works just like #if except it has no argument and evaluates itself as true only if the assembler is on its second pass through the source code. example: see also: #if1, #if, #endif, #else purpose: conditional on argument being blank. format: #ifb description: this directive works just like #if except it doesn't evaluate its argument: it simply checks to see if it is empty or blank. spaces count as blank. example: see also: #if2, #else, #if, #end #if2 %out ?gone through pass-1 ok? #endif check macro param1 #ifb param1 %out ?no param1? #else %out param1 #endif mend ... check , check 5
st7 assembler linker UM0144 61/92 a.27 #ifidn a.28 #ifdef purpose: conditional on arguments being identical. format: #ifidn description: this directive works just like #if except it compares two strings separated by a space. if identical, the result is true. example: see also: #if2, #else, #if, #end purpose: conditional on argument being defined. format: #ifdef description: this directive works just like #if except it tests for its argument being defined. example: see also: #if2, #else, #if, #end check macro param1 #ifidn param1 hello %out ?hello? #else %out ?no hello? #endif mend check macro param1 #ifdef param1 %out ?arg is ok? #else %out ?arg is undefined? #endif mend
st7 assembler linker 62/92 UM0144 a.29 #iflab a.30 #include purpose: conditional on argument being a label. format: #iflab description: this directive works just like #if except it tests that its argument is a valid, pre- defined label. example: see also: #if2, #else, #if, #end purpose: insert external source code file. format: #include ?< filename >? description: include files are source code files in the same format as normal modules but with two important differences: the first line usually reserved for the processor name is like any other source line, and they have no end directive. they are used to contain #define and macro definitions that may be used by many different modules in your program. instead of having each module declare its own set of #define and macro defini- tions, each module just includes the contents of the same #include file. the assembler goes off to the named include file and assembles this file before returning to the line after the #include directive in the former source code file. the benefit is that any alterations made to a macro must be done once, in the include file; but you'll still have to reassemble all modules referring to the changed entry. note that the filename must be inside double-quotes. example: see also: check macro param1 #iflab param1 %out ?label? #endif mend st7/ #include ?defst7.h? ... end
st7 assembler linker UM0144 63/92 a.31 intel a.32 interrupt a.33 .lall purpose: force intel-style radix specifier. format: intel description: the intel style: 0abh hexadecimal 17o or 17q octal 100b binary 17 decimal (default) $ current program counter this directive forces the intel format to be required during the assembly. example: see also: motorola, texas, zilog purpose: specifies to the debugger that a routine is an interrupt rather than a function. format: interrupt description: this directive is used with interrupt handlers and so aids the debugger in correctly searching the stack for return address of the interrupted function. example: see also: near purpose: list whole body of macro calls. format: .lall description: this directive forces the complete listing of a macro expansion each time a macro is invoked. this is the default. this directive does not generate assembly code or data. example: see also: .xall, .sall intel ld x,0ffffh public trap_handler interrupt trap_handler trap_handler iret .lall
st7 assembler linker 64/92 UM0144 a.34 .list a.35 #load purpose: enable listing (default). format: .list description: this directive switches on the listing if a previous . nolist has disabled it. the -'pa ' or -'li ' options must also have been set from the command line to generate a listing. this directive, in conjunction with the directive .nolist , can be used to control the listing of macro definitions. this directive does not generate assembly code or data. example: see also: .nolist purpose: load named object file at link time. format: #load ?pathname\filename[.ext]? description: this directive leaves a message for the linker to load the contents of the named file at the current position in the current segment. the file should be in 'straight binary' format, i.e., a direct image of the bytes you want in the object code. it should not be in motorola (.s19) or intel (.hex) format. example: see also: .list segment byte at 8000-c000 'eprom1' #load ?table.bin?
st7 assembler linker UM0144 65/92 a.36 local a.37 long purpose: define labels as local to macro. format: local description: a macro that generates loop code gives rise to an assembly problem since the loop label would be defined as many times as the macro is called. the local directive enables you to overcome this difficulty. consider the following piece of code: waiter macro ads loop ld a,ads jrne loop mend if this macro is called twice, you will be creating two labels called ' loop '. the answer is to declare very early in the macro all labels created by the macro as local . this has the effect of replacing the actual name of a local label (here ' loop ') with locxxxx where xxxx starts from 0 and increments each time a local label is used. this provides each occurrence of the labels created inside the macro with a unique identity. example: see also: macro, mend purpose: define long word in object code. format: long [,...] description: this directive forces the long word(s) in its argument list into the object code at the current address. the arguments may be composed of complex expressions, which may even include external labels. if the argument was an expression and had a value greater than ffffffff then the 32 bits of the expression are used and no errors are generated. long sends long words with the least significant byte first. it's generally used for defining data tables. synonymous with dc.l , except that long sends the low-byte first. example: see also: dc.b, dc.l, dc.w, byte, string, word waiter macro ads local loop loop led aids drone loop mend dc.l 1,$12345678 ; 0000,0001,1234,5678 long 1,$12345678 ; 0100,0000,7856,3421
st7 assembler linker 66/92 UM0144 a.38 longs a.39 macro purpose: default new label length long. format: longs description: when a label is defined, four separate attributes are defined with it: scope (inter- nally or externally defined), value (actual numerical value of the label), relativity ( absolute or relative ), and lastly, length (byte, word or long). all these attributes except length are defined explicitly before or at the end of the definition: you can force a label to be a certain length by giving a dot suffix, e.g. 'label.b' forces it to be byte length. you may also define a default state for label length: labels are created to this length unless otherwise forced with a suffix. the default is set to word at the start of the assembly, but may be changed by bytes, words or longs to the appropriate length. example: see also: bytes, words purpose: define macro template. format: macro [param-1][,param-2]... description: this directive defines a macro template that can be invoked later in the program. the label field holds the name of the macro: this name is used to invoke the rest of the macro whenever it is found in the opcode field. the arguments are dummy names for parameters that will be passed to the macro when it is used: these dummy names will be replaced by the actual calling line's arguments. note : if you don't want the definition of the macro to be listed, insert directive .nolist before the macro definition, and append directive .list after the macro definition. example: see also: mend, .lall, .sall, .xal longs lab1 equ 5 ; long length for lab1 cmp16 macro first,second,result local trylow ld a,first add a,second cp a,#0 jreq trylow cpl a trylow ld result,a mend
st7 assembler linker UM0144 67/92 a.40 mend a.41 motorola purpose: end of macro definition. format: mend description: end of macro definition. example: see also: macro purpose: force motorola-style radix specifier. format: motorola description: the motorola style: $ab hexadecimal ~17 octal %100 binary 17 decimal (default) * current program counter this directive forces the motorola format to be required during the assembly. the default format is motorola . example: see also: intel, texas, zilog cmp16 macro first,second,result local trylow ld a,first add a,second cp a,#0 jreq trylow cpl a trylow ld result,a mend motorola ld x,$ffff
st7 assembler linker 68/92 UM0144 a.42 near a.43 .nochange a.44 .nolist purpose: specifies to debuggers that the return address in the stack for functions using this directive is written over two bytes. format: near <"string"> description: this directive is used with functions called by call or callr, whose return stack address spans two bytes. every function called by call or callr must be classi- fied as near. example: see also: interrupt purpose: list original #define strings. format: .nochange description: strings named in the first argument of a #define directive will be changed to the second argument of the #define: the default is that the changed strings will be listed. if you want the original source code to be listed instead, place a .nochange directive near the start of your source code. this directive does not generate assem- bly code or data. example: see also: #define purpose: turn off listing. format: .nolist description: certain parts of your modules may not be required on a listing; this directive disables the listing until the next .list directive. the default is for the listing to be enabled. this directive, in conjunction with the directive .list , can be used to control the list- ing of macro definitions. this directive does not generate assembly code or data. example: see also: list public func near func func ret .nochange .nolist
st7 assembler linker UM0144 69/92 a.45 %out a.46 .page a.47 public purpose: output string to the console. format: %out string description: this directive prints its argument (which does not need to be enclosed in quotes) to the console. this directive does not generate assembly code or data. example: see also: purpose: perform a form feed. format: .page description: forces a new page listing. this directive does not generate assembly code or data. example: see also: purpose: make labels public. format: public description: this directive marks out given labels defined during an assembly as 'public' , i.e., accessible by other modules. this directive is related to extern ; if one module wants to use a label defined in another, then the other module must have that label declared public . a label may also be declared public as its definition by preceding the label name with a dot; it won't need to be declared in a public directive then. example: see also: extern %out hello! .page module1.asm extern print.w, print1.w ... call print ... jp print1 module2.asm public print print nop .print1 nop
st7 assembler linker 70/92 UM0144 a.48 repeat a.49 .sall purpose: assembly-time loop initiator. format: repeat description: used together with until to make assembly-time loops; it is useful for making tables etc. this directive should not be used within macros. example: see also: cequ, until purpose: suppress all body of called macro. format: .sall description: this directive forces the complete suppression of the listing of a macro expansion each time a macro is invoked. this instruction is never listed. note: this directive may produce confusing listings. example: see also: .lall, .xall repeat .sall
st7 assembler linker UM0144 71/92 a.50 segment purpose: start of new segment. format: [] segment '' [cod] description: the segment directive is very important: every module in your program will need at least one. the field may be up to 11 characters in length, and may include under- scores. the field is one of the following: align type: byte no alignment; can start on any byte boundaries word aligned to next word boundaries if necessary, i.e., 8001=8002 para aligned to the next paragraph (=16 bytes) boundary, i.e., 8001=8010 64 aligned to the next 64-byte boundary, i.e., 8001=8040 128 aligned to the next 128-byte boundary, i.e., 8001=8080 page aligned to the next page (=256 bytes) boundary, i.e., 8001=8100 long aligned to the next long-word(=4 bytes) boundary, i.e., 8001=8004 1k aligned to next 1k boundaries, i.e., 8001=8400 4k aligned to next 4k boundaries, i.e., 8001=9000 combine: at x[-y] introduces new class that starts from x and goes through to address y. address y is optional. tack this code on the end of the last segment of this class. common put the segment at the same address than other common segments that have the same name, and note the longest length segment. the optional [cod] suffix is a number from 0 to 9 - it decides into which. cod file the linker sends the contents of this class. 0 is the de- fault and is chosen if the suffix is left off. a suffix of 1-9 will cause the linker to open the [cod] suffix, and send the contents of this class into the cod file instead of the default. this allows bank switching to be supported directly at link level- different code areas at the same ad- dress can be separated out into different .cod files. see also: for more information, see section 3.4 on page 22.
st7 assembler linker 72/92 UM0144 a.51 .setdp a.52 skip purpose: set base address for direct page. format: .setdp description: if you have used an st7 processor, you'll be aware of its 'zero-page' or 'direct' addressing modes. these use addresses in the range 00..ff in shorter, faster instructions than the more general 0000..ffff versions. other processors use the same scheme, but with a twist: you can choose the 'base page' where the direct mode does not have to be in range 0000 00ff but can be from nn00..nnff where nn00 is the 'base page', loaded into a register at run-time. because the assembler cannot track what's in the base page register at run-time, you need to fill it in about the current 'base page' with the .setdp directive. at the start of the assembly, setdp defaults to 0000. example: see also: purpose: inserts given number of bytes with an initialization value. format: skip , description: this directive leaves a message for the linker that you want x number of y bytes to be inserted into the object code at this point. both the arguments must be absolute values rather than external or relative values. example: see also: .setdp $400 ld a,$401 ; direct mode chosen skip 100,$ff ; insert 100 bytes all $ff
st7 assembler linker UM0144 73/92 a.53 string a.54 subttl purpose: define a byte-level string. format: string ,[,...] description: this directive forces the byte(s) in its argument list into the object code at the current address. the arguments may be composed of complex expressions, which may even include external labels. if the argument was an expression and had a value greater than 255 the lower 8 bits of the expression are used and no errors are gener- ated. string argument(s) must be surrounded by double-quotes: these are translated into ascii and processed byte by byte. it's generally used for defining data tables. synonymous byte and dc.b. example: see also: dc.b, byte, word, long, dc.w, dc.l, fcs purpose: define a subtitle for listing heading. format: subttl ?? description: this directive is related to the title directive: its argument is used as a subtitle at the beginning of each page on a listing. we recommend that individual subtitles are generated for each module in a program, while the title is defined once in the include file called by all the modules. this directive does not generate assembly code or data. example: see also: title string 1,2,3 ; generates 01,02,03 string ?hello? ; generates 48,45,4c,4c,4f string ?hello?,0 ; generates 48,45,4c,4c,4f,00 subttl ?a/d control routines?
st7 assembler linker 74/92 UM0144 a.55 .tab a.56 texas purpose: set listing field lengths. format: .tab